<template>
  <a-modal v-model="visible"   title="新增"  @cancel='cancel' @ok='sure'>
    <a-form-model :model="item" :label-col="{span :4 }" :wrapper-col="{ span: 20 }">
      <a-form-model-item label="名称" required>
        <a-input v-model="item.name"  />
      </a-form-model-item>
      <a-form-model-item label="优先级" required>
        <a-input v-model="item.priority"  :auto-size="{ minRows: 5 ,maxRows: 5}"/>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
import ReportsEpidemicDailyService from '@/myService/ReportsEpidemicDailyService'

export default {
  name: 'CategoryItemEditAddModal',
  data(){
    return{
      visible:false,
      item:{
        categoryId:'',
        name:'',
        priority:999,
      }
    }
  },
  methods:{
    open(categoryId){
      this.item={
        categoryId:categoryId,
        name:'',
        priority:999,
      }
      this.visible=true;
    },
    cancel(){
      this.visible=false;
    },
    sure(){
      if(this.isNaturalNum(this.item.priority) && this.item.name!=='' && this.item.categoryId!==''){
        ReportsEpidemicDailyService.addCategoryKey(this.item).then(res=>{
          if(res.success){
            this.$message.success("添加成功")
            this.$emit("update")
            this.cancel()
          }
        })
      }
    },
    isNaturalNum(num) {
      if (/^[0-9]+$/.test(num) && (num >= 0)) {
        return true
      } else {
        this.$message.error("非自然数")
        return false
      }
    },
  }
}
</script>

<style scoped>

</style>